
using System.ComponentModel;
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;

using CIndicators;
using CStock;
using CUtil;
using System.Collections.Generic;

namespace CStock
{
	/// <summary>
	/// this class is abstract mainly because of the ID property, which sets also the path,which has to be either 
	/// Daily or Intraday
	/// </summary>
    public abstract partial class DataClass : DataProvider, IDataClass
    {
        #region private members


        bool bondType;
        double bondInterestRate;
        double bondIssuePrice;
        DateTime bondExpiryDate;
        DateTime bondIssueDate;
      
        IOrders orderStockBuy = new Orders();
        IOrders orderStockSell = new Orders();

	

		protected NameObjectCollection performancePerYearCollection;
		protected NameObjectCollection performanceRelativePerYearCollection;
		protected NameObjectCollection performanceBuyAndHoldPerYearCollection;

       

        NameObjectCollection equity;
        NameObjectCollection earningPerShare;
        NameObjectCollection cashFlow;
        NameObjectCollection returnOfInvestment;

      

        #endregion

        #region constructor  + init + delete

        public DataClass():base()
		{
            
			this.indicators = new Indicators();
             equity = new NameObjectCollection();
             earningPerShare = new NameObjectCollection();
             cashFlow = new NameObjectCollection();
             returnOfInvestment = new NameObjectCollection();

			
			this.oHLC = new ListQuotes();
			ResetCollections();
			
        }


        #endregion

        #region Save - Delete

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static bool DeSerialize(IDataClass myDataClass, bool intraday)
        {
            if (myDataClass == null)
            {
                System.Diagnostics.Debug.Assert(myDataClass != null, "DataClass = null, no data can be read");
                return false;
            }

            if (intraday)
            {
                Debug.Assert(false, "Not yet consistent implemented");
                return myDataClass.DeSerialize_IntradayPart();


            }
            else
            {
                object o = myDataClass;
                return myDataClass.DeSerialize(ref o);

            }



        }

   
        #endregion

        #region object overrides

        //		public object Clone()
        //		 {
        //			 //Share is lowest common Element
        //			 return this.MemberwiseClone();
        //		 }
        public new IDataClass Clone()
        {
            //Share is lowest common Element
            return this.MemberwiseClone() as IDataClass;
        }

    

        public override string ToString()
        {
            return this.Name;
            //return this.GetParameterValue(1).ToString().Trim();
        }
        
        public override int GetHashCode()
        {
            return ("DataClass" + this.ID).GetHashCode();
            // return ("DataClass" + this.iD);
        }
        #endregion

        #region others methods
        public override bool Delete()
        {
            string dirName = string.Empty;
            try
            {
                string fileName = this.path + "\\" + this.iD + ".xml";

                System.IO.File.Delete(fileName);
                dirName = this.path + "\\" + this.iD;
                System.IO.Directory.Delete(dirName, true);
                return true;




            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error deleting share file - access denied - please check access rights on file " + dirName + "; Removed file from portfolio anyhow !!! " + ex.Message);

                //Debug.Assert(false, "Error deleting " + this.iD + "; " + ex.Message);
                return false;
            }

        }
        private void CheckPath()
        {
            Debug.Assert(!String.IsNullOrEmpty(this.iD));
            if (!String.IsNullOrEmpty(this.path))
            {
                ResetPathFromConfiguration();
            }
        }

        

        #endregion

        #region Quotes
        public bool UpdateLastQuote(IQuote myNewQuote)
        {
            IQuote qu = this.QuoteCollection[this.QuoteCollection.Count - 1];
            if (myNewQuote.DATE.Day == myNewQuote.DATE.Day)
            {
                this.QuoteCollection[this.QuoteCollection.Count - 1] = myNewQuote as Quote;
            }
            return true;
        }
        #endregion

    }
}
